<template>
	<view class="address">
		<!-- 地址列表 -->
		<view class="list" v-if="this.list.length != 0">
			<view class="item" v-for="item in list" :key="item.id">
				<view class="left" @tap="selectedAddress(item)">
					<view class="text">
						<view class="name">{{ item.name }}</view>
						<view class="moren" v-if="item.defaultStatus == 1">默认</view>
					</view>
					<view class="tel">{{ item.phoneNumber }}</view>
				</view>
				<view class="right" @tap="goDel(item.id)">
					<image class="icon" src="../../../static/icons/edit.png"></image>
				</view>
			</view>
			<!-- 新增地址 -->
			<view class="add">
				<view class="btn" @tap="goAdd">
					新增地址
				</view>
			</view>
		</view>
		<view class="none" v-else>
			暂无数据
		</view>
	</view>
</template>

<script>
	import { findAllAddress } from "../../../api/user/index.js";
	import mix from "../../../mixins/index.js";
	export default {
		mixins: [mix],
		data() {
			return {
				list: [], // 地址 - 列表
			};
		},
		onLoad() {
			// 判断 - 是否登陆
			if(this.checkLogin()){
				// 查询地址列表
				findAllAddress().then(res=>{
					this.list = res.data.data.items
				})
			}
		},
		methods:{
			// 选择地址
			selectedAddress(val){
				// 本地存储 - 存储地址
				uni.setStorageSync("selectAddress",val);
				// 返回上一页
				uni.navigateBack()
			},
			// 新增地址
			goAdd(){
				uni.navigateTo({
					url: "./addAddress/addAddress"
				})
			},
			// 删除地址
			goDel(val){
				uni.navigateTo({
					url: `./addAddress/addAddress?addressId=${val}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import "./index.scss"
</style>
